import { Component, OnInit,Input,Output,Host,Inject,forwardRef } from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
import {WidgetComponent} from '../widget/widget.component'
declare var $: any;
import * as _ from 'underscore';

@Component({
  selector: 'app-pie',
  templateUrl: './pie.component.html',
  styleUrls: ['./pie.component.css']
})
export class PieComponent implements OnInit {

  expressions = [];
  curWidget={
    config:{
      values:[
        {
          name:'',
          series_type: 'line',
          type:'',
          cols:[]
        }
      ],
      chart_type:'line'
    }
  }
  dragEl=false;
  value_series_types = [
    {name: this.translate.instant('CONFIG.WIDGET.LINE'), value: 'line'},
    {name: this.translate.instant('CONFIG.WIDGET.AREA_LINE'),value:'arealine'},
    {name: this.translate.instant('CONFIG.WIDGET.STACKED_LINE'),value:'stackline'},
    {name: this.translate.instant('CONFIG.WIDGET.PERCENT_LINE'),value:'percentline'},
    {name: this.translate.instant('CONFIG.WIDGET.BAR'), value: 'bar'},
    {name: this.translate.instant('CONFIG.WIDGET.STACKED_BAR'), value: 'stackbar'},
    {name: this.translate.instant('CONFIG.WIDGET.PERCENT_BAR'), value: 'percentbar'},
    {name: this.translate.instant('CONFIG.WIDGET.POLAR_BAR'), value:'polarbar'}
  ]

  value_pie_types = [
    {name: this.translate.instant('CONFIG.WIDGET.PIE'), value: 'pie'},
    {name: this.translate.instant('CONFIG.WIDGET.DOUGHNUT'), value: 'doughnut'},
    {name: this.translate.instant('CONFIG.WIDGET.COXCOMB'), value: 'coxcomb'}
  ]

  china_map_types = [
    {name: this.translate.instant('CONFIG.WIDGET.SCATTER_MAP'), value: 'scatter'},
    {name: this.translate.instant('CONFIG.WIDGET.HEAT_MAP'), value: 'heat'},
    {name: this.translate.instant('CONFIG.WIDGET.MARK_LINE_MAP'), value: 'markLine'}
  ]


  constructor(
    private translate:TranslateService,
    @Host() @Inject(forwardRef(() => WidgetComponent)) app: WidgetComponent
  ) {
    translate.addLangs(['zh','en']);                          //添加语言支持
    translate.setDefaultLang('en');                           //设置默认语言
    let broswerLang = translate.getBrowserLang();              //获取浏览器支持的语言
    console.log(broswerLang)                                   //zh
    translate.use(broswerLang.match(/zh|en/) ? broswerLang : 'en');

    //获取父元素的属性
    console.log(app.changeChart)
    if(app.chartype=='line'){
      this.curWidget.config.values.push({
        name: '',
        series_type: 'line',
        type: 'value',
        cols: []
      });
    }
   }

   @Input() chartType:any;
  ngOnInit() {
  }

  
  add_pie_value () {
    this.curWidget.config.values.push({
        name: '',
        series_type: 'pie',
        type: '',
        cols: []
    });
  }

  public deleteValue (cols) {
    _.each(cols, function (e) {
        if (e.type == 'exp') {
            this.expressions.push(e);
        }
    });
  };

  //选择轴类型
  typeValue(value){
    console.log(value)
  }
}
